package com.fenghongzhang.module_user.provider

import android.database.AbstractCursor
import android.database.Cursor
import com.fenghongzhang.module_user.model.User

class UserCursor(private val users: List<User>) : AbstractCursor() {

    override fun getCount(): Int {
        return users.size
    }

    override fun getColumnNames(): Array<String> {
        return arrayOf("uid", "first_name", "last_name") // 根据你的User类字段进行调整
    }

    override fun getString(column: Int): String? {
        val user = users[position]
        return when (column) {
            0 -> user.uid.toString()
            1 -> "first_name"
            2 -> "last_name"
            else -> throw IllegalArgumentException("Invalid column index: $column")
        }
    }

    override fun getShort(column: Int): Short {
        throw UnsupportedOperationException("Not implemented")
    }

    override fun getInt(column: Int): Int {
        throw UnsupportedOperationException("Not implemented")
    }

    override fun getLong(column: Int): Long {
        val user = users[position]
        return when (column) {
            0 -> user.uid.toLong()
            else -> throw IllegalArgumentException("Invalid column index: $column")
        }
    }

    override fun getFloat(column: Int): Float {
        throw UnsupportedOperationException("Not implemented")
    }

    override fun getDouble(column: Int): Double {
        throw UnsupportedOperationException("Not implemented")
    }

    override fun isNull(column: Int): Boolean {
        return false
    }
}

fun convertUsersToCursor(users: List<User>): Cursor {
    return UserCursor(users)
}